package com.parkcar;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import HttpUtils.HttpParkRequest;
import Modle.ParkItemBean;
import util.BaseActivity;

/**
 * Created by Administrator on 2016/3/23.
 */
public class MonthParkActivity extends BaseActivity implements View.OnClickListener {
    private TextView park_name,park_address,mouth_need,start_time,count_time,used_money,amount_tv;
    private ImageView amount_pay,ali_pay,wx_pay;
    private int payType;
    private HttpParkRequest parkRequest;
    private long parkId;
    private ParkItemBean parkItemBean;
    private int countMonth=1;
    @Override
    protected void setUpui(Bundle arg0) {
        setContentView(R.layout.activity_month_park);
        setTitle("包月支付");
        parkId = getIntent().getLongExtra("parkId",0);

        if(parkId==0){
            toast("参数错误");
            finish();
            return ;
        }
        initView();
        getData();
    }
    private void initView(){
        park_name = (TextView) findViewById(R.id.park_name);
        park_address = (TextView) findViewById(R.id.park_address);
        mouth_need = (TextView) findViewById(R.id.mouth_need);
        start_time = (TextView) findViewById(R.id.start_time);
        count_time = (TextView) findViewById(R.id.count_time);
        used_money = (TextView) findViewById(R.id.used_money);
        amount_tv = (TextView) findViewById(R.id.amount_tv);
        amount_pay = (ImageView) findViewById(R.id.amount_pay);
        ali_pay = (ImageView) findViewById(R.id.ali_pay);
        wx_pay = (ImageView) findViewById(R.id.wx_pay);
        count_time.setOnClickListener(this);
        start_time.setOnClickListener(this);
        amount_pay.setOnClickListener(this);
        ali_pay.setOnClickListener(this);
        wx_pay.setOnClickListener(this);
    }
    private void initData(){
        park_name.setText(parkItemBean.getName());
        park_address.setText(parkItemBean.getAddress());
        mouth_need.setText("包月费用："+parkItemBean.getPrice_desc());
        used_money.setText((parkItemBean.getPrice()*countMonth)+"");
    }
    @Override
    protected void updateUI(boolean isLogin) {

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.start_time:
                toast("时间选择");
                break;
            case R.id.count_time:
                toast("月数选择");
                break;
            case R.id.amount_pay:
                if(payType!=0){
                    amount_pay.setImageResource(R.drawable.selected);
                    ali_pay.setImageResource(R.drawable.select_bg);
                    wx_pay.setImageResource(R.drawable.select_bg);
                    payType =0;
                }
                break;
            case R.id.ali_pay:
                if(payType!=1){
                    amount_pay.setImageResource(R.drawable.select_bg);
                    ali_pay.setImageResource(R.drawable.selected);
                    wx_pay.setImageResource(R.drawable.select_bg);
                    payType =1;
                }
                break;
            case R.id.wx_pay:
                if(payType!=2){
                    amount_pay.setImageResource(R.drawable.select_bg);
                    ali_pay.setImageResource(R.drawable.select_bg);
                    wx_pay.setImageResource(R.drawable.selected);
                    payType =2;
                }
                break;
        }
    }
    private void getData(){
        parkRequest = new HttpParkRequest(this,1);
        parkRequest.setmIHttpClinetListener(this);
        parkRequest.getParkDeatilById(parkId);
        parkRequest.doRequest();
    }

    @Override
    public void httpSuccessListener(Bundle successMsg) {
        super.httpSuccessListener(successMsg);
        if(mBaseResult==null){return;}
        if(parkRequest!=null&&action.equalsIgnoreCase(parkRequest.getAction())){
                if(mBaseResult.getStatus().getRetCode()==0){
                    parkItemBean = mBaseResult.toObject(ParkItemBean.class);
                    initData();
                }else{
                    toast(mBaseResult.getStatus().getMsg());
                }
        }
    }
    public void submit(View view){
        toast("包月停车预订");
    }
}
